package com.planet.handel;

import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.sms.v20210111.SmsClient;
import com.tencentcloudapi.sms.v20210111.models.*;


public class TencentSmsScript {
    public static void send(String phone,String content,String secretId,String secretKey,String sdkAppId){

        try {
            /**
             * 初始化
             */
            Credential cred = new Credential(secretId, secretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("sms.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile);
            /**
             * 组装入参
             */
            SendSmsRequest req = new SendSmsRequest();
            String[] phoneNumberSet1 = new String[]{phone};
            req.setPhoneNumberSet(phoneNumberSet1);
            req.setSmsSdkAppId(sdkAppId);
            req.setSignName("小黄鱼俊俊公众号");
            req.setTemplateId("1493335");
            String[] templateParamSet1 = {content, "2"};
            req.setTemplateParamSet(templateParamSet1);
            req.setSessionContext(IdUtil.fastSimpleUUID());
            /**
             * 发送
             */
            SendSmsResponse response = client.SendSms(req);
            System.out.println("response = " + JSON.toJSONString(response));
            System.out.println(JSON.toJSONString(response));
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
        }
    }

    public static void main(String [] args) {
//        String secretId = "AKIDVpukKfkcGengKjslmbBWfaGgqlQq0vaz";
//        String secretKey = "C8tRjofHdkeIjupUt2yhBQP9drpY1ECu";
//        String phone = "15274101410";
//        String smsSdkAppId ="1400713608";
//        String SignName = "小黄鱼俊俊公众号";
//        String templateId = "1493335";
        send("15274101410","123522","AKIDVpukKfkcGengKjslmbBWfaGgqlQq0vaz","C8tRjofHdkeIjupUt2yhBQP9drpY1ECu","1400713608");
    }
}
